<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

  <script>
    //需求：封装一个冒泡排序的函数 大到小的排序方法


    var arr = [1, 77, 33, 6, 22, 666, 111]

    function sort(arr) {
      for (var i = 0; i < arr.length; i++) {
        for (var j = 0; j < arr.length - i - 1; j++) {
          if (arr[j] < arr[j + 1]) {
            let temp = arr[j + 1];
            arr[j + 1] = arr[j];
            arr[j] = temp;
          }
        }
      }
      return arr;
    }

    let res = sort(arr);
    console.log(res);
  </script>
</body>

</html>